package ch.esn.client.view;

import ch.esn.client.presenter.view_interface.RootViewInterface;

import com.extjs.gxt.desktop.client.Desktop;
import com.extjs.gxt.desktop.client.Shortcut;
import com.extjs.gxt.desktop.client.StartMenu;
import com.extjs.gxt.desktop.client.TaskBar;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.user.client.ui.Composite;

public class RootView extends Composite implements RootViewInterface {

	private Desktop desktop = new Desktop();

	private Shortcut editProfileShortcut = new Shortcut();

	private Shortcut logoutShortcut = new Shortcut();

	public void createView() {
		initDesktopForFirstView();

		initWidget(new LayoutContainer());
	}

	public Desktop getDesktop() {
		return desktop;
	}

	public Shortcut getEditProfileShortcut() {
		return editProfileShortcut;
	}

	public Shortcut getLogoutShortcut() {
		return logoutShortcut;
	}

	private void initDesktopForFirstView() {
		maskAll();

		Shortcut s0 = new Shortcut();
		s0.setText("View your profile");
		s0.setId("view-profile-shortcut");
		// desktop.addShortcut(s0);

		editProfileShortcut = new Shortcut();
		editProfileShortcut.setText("Open your profile");
		editProfileShortcut.setId(SHORTCUT_EDIT_PROFILE_ID);
		desktop.addShortcut(editProfileShortcut);

		Shortcut s2 = new Shortcut();
		s2.setText("Change settings");
		s2.setId("change-settings-shortcut");
		desktop.addShortcut(s2);

		Shortcut s3 = new Shortcut();
		s3.setText("Search people");
		s3.setId("users-search-shortcut");
		desktop.addShortcut(s3);

		Shortcut s4 = new Shortcut();
		s4.setText("Manage friends list");
		s4.setId("users-edit-shortcut");
		desktop.addShortcut(s4);

		Shortcut s5 = new Shortcut();
		s5.setText("Mailbox");
		s5.setId("email-shortcut");
		desktop.addShortcut(s5);

		logoutShortcut.setText("Logout");
		logoutShortcut.setId(SHORTCUT_LOGOUT_ID);
		desktop.addShortcut(logoutShortcut);

		TaskBar taskBar = desktop.getTaskBar();

		StartMenu menu = taskBar.getStartMenu();
		menu.setIconStyle("user");
	}

	public void maskAll() {
		desktop.getDesktop().mask("Loading...");
		desktop.getTaskBar().mask();
	}

	public void unMaskAll() {
		desktop.getDesktop().unmask();
		desktop.getTaskBar().unmask();
	}
}
